<!DOCTYPE html>
<meta name="robots" content="noindex">
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width">

	<!-- bower:css -->
	<link rel="stylesheet" href="../../bower_components/colorbox/example1/colorbox.css"/>
	<link rel="stylesheet" href="../../bower_components/swipebox/src/css/swipebox.min.css"/>
	<link rel="stylesheet" href="../../dist/css/justifiedGallery.css"/>
	<!-- endbower -->
</head>
<body>
<p>Resize to 750px x 300px to replicate</p>
<script lang="javascript">
</script>
<div id="gallery">
	<a class="test" id="img1">
		<img src="http://dummyimage.com/1000x500/000/ffffff.png"/>
	</a>
	<a id="img2">
		<img src="http://dummyimage.com/1000x500/000/ffffff.png"/>
	</a>
	<a id="img3" class="test">
		<img src="http://dummyimage.com/1000x500/000/ffffff.png"/>
	</a>
	<a id="img4" class="test">
		<img src="http://dummyimage.com/1000x500/000/ffffff.png"/>
	</a>
	<a id="img5">
		<img src="http://dummyimage.com/1000x500/000/ffffff.png"/>
	</a>
</div>

<!-- bower:js -->
<script src="../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../bower_components/colorbox/jquery.colorbox.js"></script>
<script src="../../bower_components/swipebox/src/js/jquery.swipebox.min.js"></script>
<script src="../../dist/js/jquery.justifiedGallery.js"></script>
<!-- endbower -->

<script id="jsbin-javascript">
	var lastIdNum = 5;
	Main = function () {
		this.insert = function () {
			for (var i = 0; i < 10; i++) {
				$('#gallery').append('<a' + (Math.random() > 0.5 ? ' class="test"' : '') + ' id="img' + ++lastIdNum + '">' +
								'<img src="http://dummyimage.com/1000x500/000/ffffff.png" />' +
								'</a>');
			}
			$('#gallery').justifiedGallery('norewind');
		};

		this.start = function () {
			$('#gallery').justifiedGallery({
				rowHeight: 150,
				margins: 10,
				border: 10,
				captions: false,
				filter: '.test'
			});
			this.insert();
		};

		this.eventListener = function () {
			var self = this;
			$(window).scroll(function () {
				if ($(window).scrollTop() + $(window).height() == $(document).height()) self.insert()
			});
		};

		this.start();
		this.eventListener();
		return this;
	};

	new Main();
</script>
</body>
</html>